﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Gmis.Model;
using Gmis.IDAL;
using Gmis.DalFactory;
namespace Gmis.BLL
{
    public  class LeaveWord
    {
        private readonly ILeaveWord dal = DataAccess.CreateLeaveWord();
        public LeaveWord()
        { }
  
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Gmis.Model.LeaveWord model)
        {
            dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Gmis.Model.LeaveWord model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string Id)
        {

            return dal.Delete(Id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            return dal.DeleteList(Idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Gmis.Model.LeaveWord GetModel(string Id)
        {

            return dal.GetModel(Id);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Gmis.Model.LeaveWord> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Gmis.Model.LeaveWord> DataTableToList(DataTable dt)
        {
            List<Gmis.Model.LeaveWord> modelList = new List<Gmis.Model.LeaveWord>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Gmis.Model.LeaveWord model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Gmis.Model.LeaveWord();
                    model.Id = dt.Rows[n]["Id"].ToString();
                    model.Title = dt.Rows[n]["Title"].ToString();
                    model.contents = dt.Rows[n]["contents"].ToString();
                    model.phone = dt.Rows[n]["phone"].ToString();
                    model.contactForm = dt.Rows[n]["contactForm"].ToString();
                    if (dt.Rows[n]["leaveWordTime"].ToString() != "")
                    {
                        model.leaveWordTime = DateTime.Parse(dt.Rows[n]["leaveWordTime"].ToString());
                    }
                    if (dt.Rows[n]["replyTime"].ToString() != "")
                    {
                        model.replyTime = DateTime.Parse(dt.Rows[n]["replyTime"].ToString());
                    }
                    model.replyPerson = dt.Rows[n]["replyPerson"].ToString();
                    model.replyContents = dt.Rows[n]["replyContents"].ToString();
                    model.leaveWordPerson = dt.Rows[n]["leaveWordPerson"].ToString();
                    if (dt.Rows[n]["IsShow"].ToString() != "")
                    {
                        if ((dt.Rows[n]["IsShow"].ToString() == "1") || (dt.Rows[n]["IsShow"].ToString().ToLower() == "true"))
                        {
                            model.IsShow = true;
                        }
                        else
                        {
                            model.IsShow = false;
                        }
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }
        /// <summary>
        /// 回复
        /// </summary>
        /// <param name="model"></param>
        public bool Reply(Model.LeaveWord model)
        {
            return  dal.Reply(model);
        }
    }
}
